package com.ruibang.glass.quality.controller.semi;

import com.ruibang.glass.quality.domain.req.SemiCheckReportReq;
import com.ruibang.glass.quality.domain.req.SpecsConfigReq;
import com.ruibang.glass.quality.entity.SpecsConfig;
import com.ruibang.glass.quality.service.BcStationHqDetailService;
import com.ruibang.glass.quality.service.SpecsConfigService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import com.teaming.cloud.framework2.common.pojo.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


/**
 * <p>
 * 半成品检查规格参数配置 前端控制器
 * </p>
 *
 * @author wujie
 * @since 2024-03-12
 */
@RestController
@RequestMapping("/api/quality/specs/config")
@Api(value="半成品检查规格参数配置控制器",tags={"半成品检查规格参数配置接口"})
public class SpecsConfigController {

    @Autowired
    private SpecsConfigService specsConfigService;

    @Autowired
    private BcStationHqDetailService bcStationHqDetailService;
    
    /**
    * 通过id查询
    */
    @GetMapping("/getById/{id}")
    @ApiOperation(value="获取半成品检查规格参数配置",notes="获取半成品检查规格参数配置")
    public ResultBody getById(@PathVariable(value = "id") String id){
        return ResultBody.success(specsConfigService.getById(id));
    }

    /**
    * 新增
    */
    @PostMapping("/save")
    @ApiOperation(value="新增半成品检查规格参数配置",notes="新增半成品检查规格参数配置")
    public ResultBody save(@RequestBody SpecsConfig specsConfig){
        specsConfigService.saveInfo(specsConfig);
        return ResultBody.success();
    }

    /**
    * 通过id删除
    */
    @GetMapping("/deleteById/{id}")
    @ApiOperation(value="通过ID删除半成品检查规格参数配置",notes="通过ID删除半成品检查规格参数配置")
    public ResultBody delete(@PathVariable(value = "id") String ids){
        String[] idsStrs = ids.split(",");
        for (String id:idsStrs){
            specsConfigService.removeById(ids);
        }
        return ResultBody.success();
    }

    /**
    * 修改
    */
    @PostMapping("/update")
    @ApiOperation(value="修改半成品检查规格参数配置",notes="修改半成品检查规格参数配置")
    public ResultBody updateById(@RequestBody SpecsConfig specsConfig){
        specsConfigService.updateInfo(specsConfig);
        return ResultBody.success();
    }


    /**
    * 查询列表
    */
    @PostMapping("/list")
    @ApiOperation(value="非分页列表查询半成品检查规格参数配置",notes="非分页列表查询半成品检查规格参数配置")
    public ResultBody list(@RequestBody SpecsConfigReq specsConfig ){
        return ResultBody.success(specsConfigService.querySpecsConfig(specsConfig));
    }

    /**
    * 分页查询
    */
    @PostMapping("/page")
    @ApiOperation(value="分页列表查询半成品检查规格参数配置",notes="分页列表查询半成品检查规格参数配置")
    public ResultBody page(@RequestBody PageRequest<SpecsConfigReq> pageParam){
        return ResultBody.success(specsConfigService.queryPage(pageParam));
    }

    @GetMapping("/getGlassData")
    @ApiOperation(value="获取玻璃ID列表",notes="获取玻璃ID列表")
    public ResultBody getGlassData(@RequestParam("glassId") String glassId){
        return ResultBody.success(bcStationHqDetailService.queryGlassIdByParam(glassId));
    }

    @PostMapping("/queryCheckReportData")
    @ApiOperation(value="查询检验报告信息",notes="查询检验报告信息")
    public ResultBody queryCheckReportData(@RequestBody SemiCheckReportReq reportReq){
        return ResultBody.success(bcStationHqDetailService.queryCheckReportData(reportReq));
    }

    @PostMapping("/queryDecideResult")
    @ApiOperation(value="查询检验结果",notes="查询检验结果")
    public ResultBody queryDecideResult(@RequestBody List<String> glassCodes){
        return ResultBody.success(bcStationHqDetailService.queryDecideResult(glassCodes));
    }
}
